#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>

using namespace std;

int vis[12] = {0};
int target;

bool is_good(const vector<int>& t)
{
    return t[0] - t[1]*t[1] + t[2]*t[2]*t[2] - t[3]*t[3]*t[3]*t[3] + t[4]*t[4]*t[4]*t[4]*t[4] == target;
}

bool dfs(const vector<int>& nums, vector<int>& tmp)
{
    if(tmp.size() == 5)
        return is_good(tmp);
    for(int i=0;i<nums.size();i++)
    {
        if(!vis[i])
        {
            vis[i] = 1;
            tmp.push_back(nums[i]);
            if(dfs(nums,tmp))
                return true;
            tmp.pop_back();
            vis[i] = 0;
        }
    }
    return false;
}

int main()
{
    string s;
    while(cin>>target>>s)
    {
        if(target == 0 && s == "END")
            break;
        vector<int>nums(s.size(),0);
        for(int i=0;i<s.size();i++)
            nums[i] = s[i] - 'A' + 1;
        
        memset(vis, 0 , sizeof(vis));
        sort(nums.begin(),nums.end(), [](const int& a, const int& b){return a > b;});

        vector<int>temp;
        if(dfs(nums, temp))
        {
            for(auto& x : temp)
                cout << static_cast<char>(x+'A'-1);
            cout <<endl;
        }
        else
            cout << "no solution" <<endl;
    }
    return 0;
}